app.controller('charge', function($element, $scope, $state, rest, user,uploadConf,tipService,$location) {
    var data = angular.copy($scope.ngDialogData, {});        
    $scope.params = {};
    $scope.params2 = {};
    
    //点击确定按钮
    function json2str(o) { 
        var arr = []; 
        var fmt = function(s) { 
        if (typeof s == 'object' && s != null) return json2str(s); 
        return /^(string|number)$/.test(typeof s) ? "'" + s + "'" : s; 
        } 
        for (var i in o) arr.push("'" + i + "':" + fmt(o[i])); 
        return '{' + arr.join(',') + '}'; 
      } 
    $scope.modifySure = function() {
      // if ($scope.params.contractPics.length<1) {
        // tipService.show("body", {
            // message: "合同图片必传",
            // notice:"danger"
        // }, 3);
        // return false;
      // }     
      $scope.params.RechargeAmount = $scope.amount;
      $scope.params.OpenId = user.get('openId'),
     // $scope.params.OpenId = '1dca25eabc753b7087ef659a5d7c5c98';
      $scope.params.Phone = user.get('phone'),      
      
      rest.post({
          methodId: '1043',
          data: $scope.params,
          success: function(res) {
            console.log(res.res.data.sceneAndParams);
            $scope.params2.projectNo = 'ZG';
             $scope.params2.subject = '账户充值';
             $scope.params2.body = '账户充值';
              $scope.params2.quantity = '1';
             $scope.params2.returnUrl = 'http://' + $location.host() + ':' + $location.port() + '/#/app/fundManage/fundList';
                $scope.params2.totalFee =res.res.data.rechargeAmount;
              $scope.params2.outTradeNo = res.res.data.payId;
              $scope.params2.sceneAndParams =json2str(res.res.data.sceneAndParams);
               $scope.str = ''+'projectNo'+'='+ $scope.params2.projectNo + '&' + 'subject'+'='+$scope.params2.subject + '&' + 'body'+'='+$scope.params2.body + '&' + 'quantity'+'='+$scope.params2.quantity + '&' + 'totalFee'+'='+$scope.params2.totalFee + '&' + 'outTradeNo'+'='+$scope.params2.outTradeNo +  '&' + 'returnUrl'+'='+$scope.params2.returnUrl + '&' + 'sceneAndParams'+'='+$scope.params2.sceneAndParams + '';
            
          rest.post({
                  methodId: 'J020',
                  data: $scope.params2,
                  success: function(res) {
                    //console.log(res);
                    $('#chargehead').empty().append(res);
                  },
                  error: function() {}
              })
            
          },
          error: function() {}
      })
        // $scope.confirm({});
    }

});